/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands.connection;

import com.cea.papyrus.diagraminterchange2.di2.GraphEdge;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;


/**
 * A command to remove a shape from its parent.
 * The command can be undone or redone.
 */
public class GraphEdgeDeleteCommand extends ConnectionCommandBase {


	/**
	 * Connection instance to disconnect.
	 */
	private final GraphEdge edge;
	
	/**
	 * The original container.
	 */
	private GraphElement owner;
	
	/**
	 * original source.
	 */
	private GraphElement source;
	
	/**
	 * original target.
	 */
	private GraphElement target;

	/**
	 * Create a command that will disconnect a connection from its endpoints.
	 * 
	 * @param conn the connection instance to disconnect (non-null)
	 * 
	 * @throws IllegalArgumentException if conn is null
	 */ 
	public GraphEdgeDeleteCommand(GraphEdge conn) {
		if (conn == null) {
			throw new IllegalArgumentException();
		}
		setLabel("GraphEdge deletion");
		this.edge = conn;
	}


	/**
	 * 
	 */
	public void execute() {
		source = getSource(edge);
		target = getTarget(edge);
		owner = edge.getContainer();
		disconnectGraphEdgeAnchors(edge);
//		connection.disconnect();
	}

	/**
	 * 
	 */
	public void redo()
	{
		disconnectGraphEdgeAnchors(edge);
	}
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
	/**
	 * 
	 */
	public void undo() {
		reconnectGraphEdgeAnchors(edge, owner, source, target);
	}
	
}
